import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bxsh/widgetdiy/sample_page.dart';
import 'home_page.dart';
import 'category_page.dart';
import 'cart_page.dart';
import 'member_page.dart';

class IndexPage extends StatefulWidget {
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), title: Text('首页')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.search), title: Text('分类')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.shopping_cart), title: Text('购物车')),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.profile_circled), title: Text('个人中心')),
  ];

  final List<Widget> pages =[
    HomePage(),
    CartgoryPage(),
    CartPage(),
    MemberPage()
  ];


  int currnetIndex = 0;
  var currentPage;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    currentPage = pages[currnetIndex];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(

      bottomNavigationBar: BottomNavigationBar(items: bottomTabs,
      type: BottomNavigationBarType.fixed,
      currentIndex: currnetIndex,
      onTap: (index){
        setState(() {
          currnetIndex = index;
          currentPage = pages[currnetIndex];
        });
      },),
//      appBar: AppBar(
//        title: Text('百姓生活+'),
//      ),
     // body: currentPage,
      body: IndexedStack(
        index: currnetIndex,
        children: pages,
      ),
    );
  }
}
